package javabasics.task1;

import java.util.Scanner;
import java.util.ArrayList;

public class PrimeNumber {

	public static void main(String[] args) {
	  int num = readInput();

	  ArrayList<Integer> res = findPrimeNumbers(num);

	  for (Integer r : res){
			System.out.print(r + " ");
	  }
	}

	private static int readInput() {
		int num = 0;
		System.out.println("Input your number:");
		Scanner reader = new Scanner(System.in);
		while (!reader.hasNextInt()) {
			System.out.println("Invalid number. Try another one:");
			reader = new Scanner(System.in);
		}
		num = reader.nextInt();
		reader.close();
		return num;
	}

	private static ArrayList<Integer> findPrimeNumbers(int number) {
		ArrayList<Integer> primeNumbers = new ArrayList<Integer>();
		for (int i = 2; i <= number; i++) {
			int a = 0;
			for (int j = 2; j < i; j++)
				if (i % j == 0) {
					a++;
				}
			if (a == 0) {
				primeNumbers.add(i);
			}
		}
		return primeNumbers;
	}
}